﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using tenpay;

public partial class Payment_tenpay_return_url : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //密钥
        string key = "c2fab55d3ac392fa7399376bf0c4ea61";

        //创建PayResponseHandler实例
        PayResponseHandler resHandler = new PayResponseHandler(Context);

        resHandler.setKey(key);

        //判断签名
        if (resHandler.isTenpaySign())
        {
            //交易单号
            string transaction_id = resHandler.getParameter("transaction_id");

            //金额金额,以分为单位
            string total_fee = resHandler.getParameter("total_fee");

            //支付结果
            string pay_result = resHandler.getParameter("pay_result");

            if ("0".Equals(pay_result))
            {
                //------------------------------
                //处理业务开始
                //------------------------------ 

                //注意交易单不要重复处理
                //注意判断返回金额

                string order_no = resHandler.getParameter("sp_billno");
                BLL.BLLshoplist2 bll = new BLL.BLLshoplist2();
                Model.ordertable model = bll.GetModelOrderTable(order_no);
                model._count = 2;//在线支付方式：财付通
                model._address = transaction_id;//支付宝交易号
                model._paystate = 1;//订单支付成功
                bll.UpdateOrderTable(model);

                //------------------------------
                //处理业务完毕
                //------------------------------

                //调用doShow, 打印meta值跟js代码,告诉财付通处理成功,并在用户浏览器显示$show页面.
                resHandler.doShow("http://www.51maihua.cn/Payment/tenpay/show.aspx");
            }
            else
            {
                //当做不成功处理
                Response.Write("支付失败");
            }

        }
        else
        {
            Response.Write("认证签名失败");
            //string debugInfo = resHandler.getDebugInfo();
            //Response.Write("<br/>debugInfo:" + debugInfo);
        }
    }
}
